

import info.gridworld.actor.Bug;
import info.gridworld.grid.Location;

public class TriangleBug extends Bug {
	
	private int baseSteps;
	private int currentSteps;

	
	public TriangleBug(int baseSteps){
		this.baseSteps = baseSteps;
		this.currentSteps = 0;
	}
	
	public void act(){
		if (canMove()){
			move();
		}
	}
	
	public void move(){
		
		if (currentSteps <= (2*baseSteps)){
			Location currentLocation = getLocation();
			
			if (currentSteps<baseSteps){
				moveTo(new Location(currentLocation.getRow(), currentLocation.getCol()- 1));
			} else if (currentSteps == baseSteps){
				setDirection(Location.NORTHEAST);
			}
			else if (currentSteps < (1.5*baseSteps)){
				moveTo(new Location(currentLocation.getRow()- 1, currentLocation.getCol() + 1));
			} else if (currentSteps == (1.5*baseSteps)){
				moveTo(new Location(currentLocation.getRow()- 1, currentLocation.getCol() + 1));
				setDirection(Location.SOUTHEAST);
			}
			else {
				moveTo(new Location(currentLocation.getRow() + 1, currentLocation.getCol() + 1));
			}
		
			currentSteps++;
		}
		
		else {
			currentSteps = 0;
		}
	}
	
	public void turn(){
			setDirection(Location.NORTHEAST);
	}

}
